package com.tarena.luban.worker.server.repo;

import com.tarena.luban.worker.server.bo.WorkerAreaBO;
import com.tarena.luban.worker.server.dao.WorkerAreaDao;
import com.tarena.luban.worker.server.repo.converter.WorkerAreaConverter;
import com.tarena.luban.worker.server.repository.WorkerAreaRepository;
import com.tarena.tp.luban.worker.po.WorkerArea;
import com.tarena.tp.luban.worker.server.dto.param.WorkerAreaParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author java@tedu.cn
 * @version 1.0
 */
@Repository
public class WorkerAreaRepoImpl implements WorkerAreaRepository {
    @Autowired
    private WorkerAreaDao workerAreaDao;
    @Autowired
    private WorkerAreaConverter workerAreaConverter;
    @Override
    public void deleteByUserId(Long userId) {
        workerAreaDao.deleteByUserId(userId);
    }

    @Override
    public void save(WorkerAreaParam workerAreaParam) {
        //先转化
        WorkerArea workerArea = workerAreaConverter.param2po(workerAreaParam);
        workerAreaDao.insert(workerArea);
    }

    @Override
    public List<WorkerAreaBO> selectByUserId(Long userId) {
        //po 返回
        List<WorkerArea> workerAreas= workerAreaDao.selectAreaByUserId(userId);
        //转化
        return workerAreaConverter.poList2BoList(workerAreas);
    }
}
